package com.fangyi.yunmusic.controller;

import com.fangyi.yunmusic.enums.FileTypeEnum;
import com.fangyi.yunmusic.utils.FileUploadClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
public class UploadController {


    @Autowired
    private FileUploadClient fileUploadClient;

    /**
     * 上传成功，则返回文件路径，以及文件ID
     * @param file
     * @return
     */
    @PostMapping("/cover/playlist")
    public Object uploadPlaylistCover(@RequestParam MultipartFile file){
        FileUploadClient.FileMessageResponse response = fileUploadClient.uploadToFarService(file, FileTypeEnum.PLAYLIST_COVER);
        return response;
    }

    @PostMapping("/cover/artist")
    public Object uploadArtistCover(@RequestParam MultipartFile file){
        FileUploadClient.FileMessageResponse response = fileUploadClient.uploadToFarService(file, FileTypeEnum.SINGER_COVER);
        return response;
    }

    @PostMapping("/cover/album")
    public Object uploadAlbumCover(@RequestParam MultipartFile file){
        FileUploadClient.FileMessageResponse response = fileUploadClient.uploadToFarService(file, FileTypeEnum.ALBUM_COVER);
        return response;
    }

    @PostMapping("/avatar/user")
    public Object uploadUserAvatar(@RequestParam MultipartFile file){
        FileUploadClient.FileMessageResponse response = fileUploadClient.uploadToFarService(file, FileTypeEnum.USER_AVATAR);
        return response;
    }

    @PostMapping("/song")
    public Object uploadSong(@RequestParam MultipartFile file){
        FileUploadClient.FileMessageResponse response = fileUploadClient.uploadToFarService(file, FileTypeEnum.SONG);
        return response;
    }

}
